package com.lzh.educms.controller;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lzh.commonutils.CommonResult;
import com.lzh.educms.entity.CrmBanner;
import com.lzh.educms.service.CrmBannerService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 * 首页banner表 前端控制器
 * </p>
 *
 * @author lizuhu
 * @since 2021-05-16
 * 后台管理
 */
@RestController
@RequestMapping("/eduCms/admin")
@CrossOrigin
public class AdminBannerController {
    @Autowired
    private CrmBannerService crmBannerService;

    @ApiOperation(value = "获取所有轮播图")
    @GetMapping("/getAll")
    public CommonResult getBanner() {
        List<CrmBanner> list = crmBannerService.list(null);
        return CommonResult.ok().data("list",list);
    }
    @ApiOperation(value = "根据id查询轮播图")
    @GetMapping("/getById")
    public CommonResult get(@RequestParam String id) {
       CrmBanner banner = crmBannerService.getById(id);
        return CommonResult.ok().data("item",banner);
    }
    @ApiOperation(value = "添加轮播图")
    @PostMapping("/save")
    public CommonResult save(@RequestBody CrmBanner crmBanner) {
        crmBannerService.save(crmBanner);
        return  CommonResult.ok();
    }
    @ApiOperation(value = "修改轮播图")
    @PutMapping("/updateById")
    public CommonResult updateById(@RequestBody CrmBanner crmBanner) {
        crmBannerService.updateById(crmBanner);
        return CommonResult.ok();
    }
    @ApiOperation(value = "删除轮播图")
    @DeleteMapping("/deleteById")
    public CommonResult deleteById(@RequestParam String id) {
        boolean result = crmBannerService.removeBannerById(id);
        if (result) return CommonResult.ok();
        else return CommonResult.error().message("图片删除失败");
    }

}

